/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.peersim.pastry.initializers;

import com.google.code.peersim.pastry.protocol.PastryNode;
import com.google.code.peersim.pastry.protocol.PastryProtocol;
import peersim.core.Control;
import peersim.core.Network;
import peersim.core.Node;
import peersim.dynamics.NodeInitializer;

/**
 * This PeerSim {@link Control} class is in charge of initializing the {@link PastryProtocol}
 * instances running on every active node in the simulated environment. A {@link PastryProtocol}
 * instance is initialized invoking its {@link PastryProtocol#init()} method.
 *
 * @see PastryProtocol#init() 
 *
 * @author frusso
 * @version 0.1
 * @since 0.1
 */
public class PastryIdInitializer implements Control, NodeInitializer {

  /**
   * Constructor.
   * 
   * @param prefix The prefix used to access configuration properties
   */
  public PastryIdInitializer(String prefix) {
    super();
  }

  /**
   * Invokes the {@link PastryProtocol#init()} over every {@link Node} instance
   * found in the {@link Network}
   *
   * {@inheritDoc}
   */
  @Override
  public boolean execute() {
    boolean stop = false;
    int n = Network.size();
    for(int i=0; i<n; i++) {
      PastryNode node = (PastryNode) Network.get(i);
      node.initPastry();
    }
    return stop;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void initialize(Node n) {
    PastryNode node = (PastryNode)n;
    node.initPastry();
  }
}